package com.sx.zongzhi.adapter;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.zongzhi.R;
import com.sx.zongzhi.bean.HouseUserInfo;
import com.sx.zongzhi.net.ServiceFactory;
import com.sx.zongzhi.utils.BaseUtil;

import java.io.File;
import java.util.List;


/**
 * Created by XZY on 2017/11/23.
 * 租客adapter
 */

public class RenterAdapter extends BaseQuickAdapter<HouseUserInfo,BaseViewHolder> {

    private Context context;

    public RenterAdapter(Context context, @LayoutRes int layoutResId, @Nullable List<HouseUserInfo> data) {
        super(layoutResId, data);
        this.context=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, HouseUserInfo item) {
        ImageView iv_img = helper.getView(R.id.imv_imgUrl);
        RequestOptions options = new RequestOptions().centerCrop()
                .placeholder(R.mipmap.head_default)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .circleCrop()
                .error(R.mipmap.head_default);
        Glide.with(context)
                .load(ServiceFactory.NEW_API_BASE_URL+ File.separator + item.getImgUrl())
                .apply(options)
                .into(iv_img);
        helper.setText(R.id.tv_genderName,BaseUtil.isEmpty(item.getGenderName()) ? "" : item.getGenderName());
        helper.setText(R.id.tv_age,BaseUtil.isEmpty(item.getAge()) ? "":item.getAge()+"岁");
        helper.setText(R.id.tv_personCategory,BaseUtil.isEmpty(item.getPersonCategory()) ? "" : item.getPersonCategory());
        helper.setText(R.id.tv_name,BaseUtil.isEmpty(item.getName()) ? "":item.getName());
        helper.setText(R.id.tv_idCardNo,BaseUtil.isEmpty(item.getIdCardNo()) ? "":"("+item.getIdCardNo()+")");
    }
}
